package com.os.opencv.java.chapter11;

import org.opencv.core.*;
import org.opencv.features2d.Features2d;
import org.opencv.features2d.SIFT;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Sift {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //读取图像并在屏幕上显示
        Mat src = Imgcodecs.imread("pics/face.jpg", Imgproc.COLOR_BGR2GRAY);
        Mat dst = new Mat();
        Imgproc.cvtColor(src, dst, Imgproc.COLOR_BGR2GRAY);
        HighGui.imshow("gray", dst);
        HighGui.waitKey(0);

        //用sift算法检测关键点
        SIFT sift = SIFT.create(500);  //最多500个关键点
        MatOfKeyPoint pt = new MatOfKeyPoint();
        sift.detect(src, pt);  //pt为结果

        //在dst上画出关键点并在屏幕上显示
        Features2d.drawKeypoints(src, pt, dst, new Scalar(0,0,255), Features2d.DrawMatchesFlags_DRAW_RICH_KEYPOINTS);
        HighGui.imshow("sift", dst);
        HighGui.waitKey(0);
        System.exit(0);
    }
}
